package com.example.service.impl;

import com.example.model.Product;
import com.example.dao.ProductMapper;
import com.example.modelDTO.ProductDTO;
import com.example.modelDTO.converter.ProductConverter;
import com.example.service.IProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Hello
 * @since 2024-07-09
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {
    @Autowired
    ProductMapper productMapper;

    public List<ProductDTO> getAllListedProducts(){
        return productMapper.getAllListedProduct().stream()
                .map(ProductConverter::toDto)
                .collect(Collectors.toList());
    }

    /*public List<ProductDTO> getAllByRestaurantId(String restaurantIdStr){
        List<Product> productList=productMapper.getAllByRestaurantId(restaurantIdStr);
        List<ProductDTO> productDTOList=new ArrayList<>();
        for(Product product:productList){
            productDTOList.add(new ProductDTO(
                    product.getProductName(),
                    product.getProductImage(),
                    product.getProductPoints(),
                    product.getStock(),
                    product.getSold()));
        }
        return productDTOList;
    }*/
}
